//
//  FRFocusViewController.m
//  Live
//
//  Created by 徐芙蓉 on 2017/7/26.
//  Copyright © 2017年 Afra. All rights reserved.
//

#import "FRFocusViewController.h"
#import "FRLiveCell.h"
#import "FRPlayerViewController.h"

static NSString *identifier = @"FRLiveCell";

@interface FRFocusViewController ()
@property (nonatomic, strong) NSArray *datalist;
@end

@implementation FRFocusViewController

//-(NSMutableArray *)datalist
//{
//    if (!_datalist) {
//        _datalist = [NSMutableArray array];
//        
//    }
//    return _datalist;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self initUI];
    [self loadData];

}

-(void)initUI
{
    [self.tableView registerNib:[UINib nibWithNibName:@"FRLiveCell" bundle:nil] forCellReuseIdentifier:identifier];
}

-(void)loadData
{
    FRLive *live = [[FRLive alloc] init];
    FRCreator *create = [[FRCreator alloc] init];
    live.city = @"上海";
    live.onlineUsers = 100;
    live.streamAddr = @"rtmp://play.bcelive.com/live/lss-hhff66si55x46nku";
    
    live.creator = create;
    create.nick = @"Afra";
    create.portrait = @"focus";
    
    self.datalist = @[live];
    [self.tableView reloadData];
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.datalist.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FRLiveCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell==nil) {
        
        cell = [[FRLiveCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    NSLog(@"datalist = %@",self.datalist[indexPath.row]);
    cell.live = self.datalist[indexPath.row];
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 70 + SCREEN_WIDTH;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    FRLive *live = self.datalist[indexPath.row];
    
    FRPlayerViewController *playerVC = [[FRPlayerViewController alloc] init];
    playerVC.live = live;
    
    [self.navigationController pushViewController:playerVC animated:YES];
    
    
    /* 系统自带的播放器播放不了直播的内容
     
     MPMoviePlayerViewController *movieVC = [[MPMoviePlayerController alloc]initWithContentURL:[NSURL URLWithString:live.streamAddr]];
     [self presentViewController:movieVC animated:YES completion:nil];
     */
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
